<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<%@include file="include/header.jsp" %>
</head>
<body>
<%@include file="include/menu.jsp" %>
<%		
		Persona vo = (Persona)session.getAttribute("user");
		
		if (vo== null){
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
			return;
		}
	  %>
</head>
<body>
<div class="container">
		<div class="hero-unit">
	    	<h2 align="center"><strong>Consulta de Morosos</strong></h2><br>
	    </div>
	<%@page import="java.util.ArrayList,condominios.modelo.Cuota,java.text.SimpleDateFormat, java.text.DecimalFormat,java.text.DecimalFormatSymbols, java.util.ArrayList,condominios.modelo.Persona"%>


		<div class="row">
			<div class="col-md-10 col-md-offset-1">
		<%	
			DecimalFormatSymbols simbolos = new DecimalFormatSymbols();
			simbolos.setDecimalSeparator('.');
			java.text.DateFormat dtf = new SimpleDateFormat("dd/MM/yyyy");
			DecimalFormat def = new DecimalFormat("###,###.00",simbolos);
			
			ArrayList<Cuota> cuotasFull = (ArrayList<Cuota>) request.getAttribute("CUOTAS");
			if (cuotasFull != null) {%>
	
			<div class="table-responsive">
			<p>La cantidad de registros encontrados son: <%=cuotasFull.size()%></p>
			<table class="table table-striped table-bordered table-condensed">
  				<tr class="active">
  					<th>Id Cuota</th>
  					<th>Edificio</th>
  					<th># Vivienda</th>
  					<th>Residente</th>
  					<th># Cuota</th>
  					<th>Periodo</th>
  					<th>Importe</th>
  					<th>Fecha de Vencimiento</th>
  				</tr>
  				<% 
  				int minFila = (int) request.getAttribute("MINROW");
  				int maxFila = (int) request.getAttribute("MAXROW");
  			
  				for (int i=minFila; i<=maxFila; i++) {
  				%>
  				<tr>
  					<td align="center"><%=cuotasFull.get(i).getIdCuota()%></td>
  					<td><%=cuotasFull.get(i).getDatosUbicacion().getDescripUbicacion()%></td>
  					<td align="center"><%=cuotasFull.get(i).getDatosVivienda().getNumero()%></td>
  					<td><%=cuotasFull.get(i).getDatosPersona().getobtenerNombresCompletos()%></td>
  					<td align="center"><%=cuotasFull.get(i).getNumCuota()%></td>
  					<td align="rigth"><%=cuotasFull.get(i).getPeriodoCompleto()%></td>
  					<td>S/.<%=def.format(cuotasFull.get(i).getImporte())%></td>
  					<td align="center"><%=dtf.format(cuotasFull.get(i).getFechaVencimiento())%></td>
  					
  				</tr>
  				<%
  				}
  				%>
  					
			</table>
			</div>
		
			<%
  				}
  				%>
		</div>
		
		</form>				
			<div class="row">		
  			<div class="col-md-4 col-md-offset-1" align="left">
  			<form method="post" action="MorosoPaginarServlet">
  			
  				<%int numPag = (int) request.getAttribute("NUMPAG");%>
  				<nav>
			  	<ul class="pagination">
			  	<%if (numPag ==1) {
			  	%>
			  		 <li class="disabled">
			      		<a href="<%=request.getContextPath()%>/MorosoPaginarServlet?idPag=<%=numPag%>" aria-label="Previous">
			        		<span aria-hidden="true">&laquo;</span>
			      		</a>
			    	</li>
			  	<%	
			  	} else {%>
			  		<li>
			      		<a href="<%=request.getContextPath()%>/MorosoPaginarServlet?idPag=<%=numPag-1%>" aria-label="Previous">
			        		<span aria-hidden="true">&laquo;</span>
			      		</a>
			    	</li>
			  	
			  	<%	
			  	}
			  		%>			  				   
			    <% 
  				int numPaginas = (int) request.getAttribute("NUMEROPAGINAS");
			    
  				
  				for (int i=1; i<=numPaginas; i++) {
  					if (i==numPag) {
  						%>
  					    <li class="active"><a href="<%=request.getContextPath()%>/MorosoPaginarServlet?idPag=<%=i%>"><%=i%></a></li>
  							    
  					    <% } 
  					    else {
  					    %>
					    <li><a href="<%=request.getContextPath()%>/MorosoPaginarServlet?idPag=<%=i%>"><%=i%></a></li>
							    
					    <% }
  					
  						}%>
  						
  				<%if (numPag == numPaginas) {
			  	%>
			  		 <li class="disabled">
			      		<a href="<%=request.getContextPath()%>/MorosoPaginarServlet?idPag=<%=numPag%>" aria-label="Next">
			        		<span aria-hidden="true">&raquo;</span>
			      		</a>
			    	</li>
			  	<%	
			  	} else {%>
			  		<li>
			      		<a href="<%=request.getContextPath()%>/MorosoPaginarServlet?idPag=<%=numPag+1%>" aria-label="Next">
			        		<span aria-hidden="true">&raquo;</span>
			      		</a>
			    	</li>			  	
			  	<%	
			  	}
			  		%>		
			  </ul>
			</nav>
			</form>
  			</div>
  		<div class="col-md-6" align="right">
  			<form id = "formaPaginar" method="post" action="MorosoCambiarFilasServlet">
  				Items por pagina: <select id= "selCanId" name = "selCanId" onchange="irServletBuscar()">
  					<%if (session.getAttribute("CANTIDAD_FILAS").equals(10)){
  						%>
  					
					<option value="10">10</option>
					<option value="5">5</option>
					<option value="20">20</option>
					<%} 
  					else {
  					
  						if(session.getAttribute("CANTIDAD_FILAS").equals(20)){%>
  						<option value="20">20</option>
						<option value="5">5</option>
						<option value="10">10</option>	
  						<%	
  						}
  						else {%>
  							<option value="5">5</option>
  							<option value="10">10</option>
  							<option value="20">20</option><%
  						}						
  					}					
					%>					
				</select>
				<p id="demo"></p>
				<script>
				function irServletBuscar() {	
					
				    document.getElementById("formaPaginar").submit();				    				    
				}
								
				</script> 
				</form>			 
  				</div>
			</div>		
		</div>								
	</div>
</body>

	<footer>
	 <div class="container">
		 <div class="row">		
	  		<div class="col-md-12" align="center">			 	
	        		<p>&copy; Java Tigers 2015</p>				
			</div>
				
		</div>
		
	</div>
	 </footer>
</html>